package com.fatdetection.demo.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fatdetection.demo.bean.Consult;
import com.fatdetection.demo.mapper.ConsultMapper;
import com.fatdetection.demo.service.ConsultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConsultServiceImpl implements ConsultService {
    @Autowired
    ConsultMapper mapper;

    @Override
    public Page<Consult> selectPage(Integer current, Integer size) {
        Page<Consult> page = new Page<>(current, size);
        return mapper.selectPage(page, null);
    }

    @Override
    public boolean insert(Consult data) {
        return mapper.insert(data) == 1;
    }

    @Override
    public boolean del(Integer id) {
        return mapper.delete(new QueryWrapper<Consult>().eq("id", id)) == 1;
    }

    @Override
    public boolean update(Consult data) {
        return mapper.update(data,
                new UpdateWrapper<Consult>()
                        .eq("id", data.getId())) == 1;
    }

    @Override
    public Consult getOne(String key, String val) {
        return mapper.selectOne(new QueryWrapper<Consult>().eq(key, val));
    }

    @Override
    public List<Consult> getAll() {
        return mapper.selectList(null);
    }
}
